Repository navigation
docs(spanner): improve Getting Started samples following code-for-llm - #1
Open
thecodewreck wants to merge 2 commits into
Open
thecodewreck wants to merge 2 commits into
thecodewreck wants to merge 2 commits into
Conversation
Applies the code-for-llm guidelines to the 19 regions that the Spanner getting-started page includes from snippets.py, pg_snippets.py and quickstart.py. - State arguments, raised exceptions and recovery steps in docstrings, or in comments where the region starts inside a function body. - Add type annotations, region-local imports, named row unpacking, and the request= and timeout= keywords. - Raise ValueError in write_with_dml_transaction for a missing album row, a NULL budget, or a budget below the transfer amount. read_write_transaction already raises ValueError for a low budget. Function names, parameters, region tags, SQL and printed output are unchanged.
Removes the 'from google.cloud import spanner' lines added inside 18 getting-started regions. snippets.py and pg_snippets.py already import spanner at module level. quickstart.py keeps its import, which was there before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Upgrades the 19 Cloud Spanner Getting Started code snippets in
snippets.py,pg_snippets.pyandquickstart.pyfollowingcode-for-llmbest practices while preserving all existing function signatures, region tags, schemas, SQL statements, andstdoutoutput.Key Improvements
[START ...]regions: Added Google-style docstrings (Args:,Raises:withRecovery:) to the 14 regions that contain theirdef, and contract comments or a callback docstring to the 5 regions that start inside a function body. Each one names thegoogle.api_core.exceptionsclass raised for a missing instance, database, table, column, index or row, and for an existing database, column or index.from google.cloud import spannerinside each region, replacedformat(*row)with named row unpacking, and passedrequest=andtimeout=as keywords.write_with_dml_transaction: The transfer now raisesValueErrorwhen an album row is missing,MarketingBudgetis NULL, or the second album has less than the transfer amount. Before, it raisedIndexError, raisedTypeError, or returned without doing anything.read_write_transactionin the same file already raisesValueErrorfor a low budget. Output on success is unchanged.add_scoring_index(the function isadd_storing_index).Verification
google-cloud-spanner==3.71.0(the version pinned insamples/samples/requirements.txt)black==23.7.0,ruff formatandflake8with the flags fromsamples/samples/noxfile.py: PASSquickstart_test.py,snippets_test.pyandpg_snippets_test.py(22 tests) on the Cloud Spanner Emulator: PASS